/* GUI CONVERTED from rsssmtb.p (converter v1.76) Fri Sep  6 04:59:32 2002 */
/* rsssmtb.p - Supplier Shipping Schedules Detail Maintenence               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/* $Revision: 1.48 $                                                         */
/*V8:ConvertMode=Maintenance                                                */
/* REVISION: 9.0      CREATED:       05/15/98   BY: *K1QZ* Suresh Nayak     */
/* REVISION: 9.0      MODIFIED:      03/13/99   BY: *M0BD* Alfred Tan       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb              */
/* REVISION: 9.1      LAST MODIFIED: 01/03/01   BY: *M0YD* Rajesh Thomas    */
/* REVISION: 9.1      LAST MODIFIED: 06/12/02   BY: *P089* Lena Lim         */
/* Revision: 1.44     BY: Vinod Nair            DATE: 06/14/02  ECO: *N1HR*  */
/* Revision: 1.46     BY: K Paneesh             DATE: 08/26/02  ECO: *N1QX*  */
/* $Revision: 1.48 $    BY: Santosh Rao           DATE: 09/03/02  ECO: *N1PP*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */

/* DISPLAY TITLE */
{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter sch_recid   as recid                      no-undo.
define output parameter schd_recid as recid                      no-undo.
define new shared variable cmtindx like cmt_indx.
define variable i                  as integer                    no-undo.
define variable schddet_recid      as recid                      no-undo.
define variable where_we_are       as integer                    no-undo.
define variable del-yn             like mfc_logical              no-undo.
define variable cmmts              like mfc_logical label "Item" no-undo.
define variable prior_cum_qty      like schd_upd_qty             no-undo.
define variable new_schd_det       like mfc_logical              no-undo.
define variable l_ref_time         as character format "99:99"   no-undo.
define variable l_dummy_length     as character format "999:99"  no-undo.
define variable l_msgnbr           as integer                    no-undo.
define variable l_schd_time        like schd_time                no-undo.
define variable l_schd_interval    like schd_interval            no-undo.
define variable l_schd_ref         like schd_reference           no-undo.
define variable l_date             as date                       no-undo.
define variable new_date           like schd_date                no-undo.
define variable l_old_schd_upd_qty like schd_upd_qty             no-undo.
define variable l_new_schd_upd_qty like schd_upd_qty             no-undo.
define variable l_old_schd_fc_qual like schd_fc_qual             no-undo.
define variable l_new_schd_fc_qual like schd_fc_qual             no-undo.

for first rsc_ctrl no-lock:
end. /* FOR FIRST rsc_ctrl */
if not available rsc_ctrl
then do transaction:
   create rsc_ctrl.
end. /* END TRANSACTION */

for first sch_mstr
   where recid(sch_mstr) = sch_recid
   no-lock:
end. /* FOR FIRST sch_mstr */

for first pod_det
   where pod_nbr = sch_nbr
   and pod_line  = sch_line
   no-lock:
end. /* FOR FIRST pod_det */

for each schd_det
   where schd_type     = sch_type
   and   schd_nbr      = sch_nbr
   and   schd_line     = sch_line
   and   schd_rlse_id  = sch_rlse_id
   and   schd_interval = "D"
   exclusive-lock:

   if sch_cumulative
   then
      schd_upd_qty = schd_cum_qty.
   else
      schd_upd_qty = schd_discr_qty.

end.  /* FOR EACH schd_det */

FORM /*GUI*/ 
   space (5)
   schd_date
   schd_time
   schd_reference
   schd_upd_qty
   schd_fc_qual
   with frame sched_det down centered
   /*V8+*/ attr-space width 80
   no-validate title color normal
   (getFrameTitle("SHIPPING_SCHEDULE_DETAIL_DATA",41)) THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame sched_det:handle).

pause 0.
mainloop:

do transaction with frame sched_det:

   clear frame sched_det all no-pause.
   view frame sched_det.
   for first schd_det
      where schd_type     = sch_type
      and   schd_nbr      = sch_nbr
      and   schd_line     = sch_line
      and   schd_rlse_id  = sch_rlse_id
      and   schd_interval = "D"
      no-lock:
   end. /* FOR FIRST schd_det */

   i = 0.

   do while i < frame-down and available schd_det:
      display
         schd_date
         schd_time
         schd_reference
         schd_upd_qty
         schd_fc_qual
      with frame sched_det.

      i = i + 1.

      if i < frame-down then down 1.
      find next schd_det where schd_type = sch_type
         and schd_nbr = sch_nbr
         and schd_line = sch_line
         and schd_rlse_id = sch_rlse_id
         and schd_interval = "D"
      no-lock no-error.
   end. /* END OF DO WHILE i < FRAME-DOWN AND AVAILABLE schd_det */

   up frame-line - 1.
   for first schd_det
      where schd_type     = sch_type
      and   schd_nbr      = sch_nbr
      and   schd_line     = sch_line
      and   schd_rlse_id  = sch_rlse_id
      and   schd_interval = "D"
      no-lock:
   end. /* FOR FIRST schd_det */

   /* CALLED sched_update TO UPDATE TYPE 4 sch_pcr_qty AND        */
   /* sch_pcs_date WHEN USER EXITS WITHOUT UPDATING LINE DETAILS. */

   run sched_update
     (input recid(sch_mstr),
      input pod_curr_rlse_id[1],
      input new_date,
      input l_old_schd_upd_qty,
      input l_new_schd_upd_qty,
      input l_old_schd_fc_qual,
      input l_new_schd_fc_qual,
      input l_schd_time,
      input l_schd_interval,
      input l_schd_ref).

   detail-loop:
   repeat with frame sched_det:
/*GUI*/ if global-beam-me-up then undo, leave.


      ststatus = stline[1].
      status input ststatus.
      pause before-hide.
      prompt-for schd_date schd_time schd_reference
         go-on(F9 F10 CURSOR-UP CURSOR-DOWN).
      pause 0.

      if frame-field = "schd_date"
      then
         next-prompt schd_date.
      else
         if frame-field = "schd_time"
      then
         next-prompt schd_time.
      else
         if frame-field = "schd_reference"
      then
         next-prompt schd_reference.

      assign
         l_ref_time  = substring(string(time,"HH:MM"),1,2)
                     + substring(string(time,"HH:MM"),4,2)
         l_msgnbr    = 0
         l_schd_time = input schd_time.

      /* FSTIMCHK WILL RETURN ONE OF TWO POTENTIAL  */
      /* ERRORS.  #30 IS FOR MINUTES > 59.  #69     */
      /* INDICATES NON-NUMERIC INPUT, IN WHICH CASE */
      /* WE WANT TO PRESERVE AND REDISPLAY THE USER */
      /* INPUT.                                     */

      {gprun.i ""fstimchk.p""
         "(input  ""T"",
           input l_schd_time,
           input  """",
           output l_ref_time,
           output l_dummy_length,
           output l_msgnbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if l_msgnbr <> 0
      then do:
         {pxmsg.i &MSGNUM=l_msgnbr &ERRORLEVEL=3}
         next-prompt schd_time with frame sched_det.
         undo, retry.
      end. /* END OF IF l_msgnbr <> 0 */

      if input schd_date = ?
      then do:
         {pxmsg.i &MSGNUM=27 &ERRORLEVEL=3} /* INVALID DATE */
         next-prompt schd_date with frame sched_det.
         undo , retry.
      end. /* END OF IF schd_date = ? */

      do while
            lastkey    = keycode("F9")
            or lastkey = keycode("CURSOR-UP")
            or lastkey = keycode("F10")
            or lastkey = keycode("CURSOR-DOWN")
            on endkey undo , leave detail-loop:

         if available schd_det
         then do:

            if lastkey = keycode("F9")
               or lastkey = keycode("CURSOR-UP")
            then do:
               find prev schd_det
                  where schd_type     = sch_type
                  and   schd_nbr      = sch_nbr
                  and   schd_line     = sch_line
                  and   schd_rlse_id  = sch_rlse_id
                  and   schd_interval = "D"
               exclusive-lock no-error.

               if available schd_det
               then do:
                  up 1.
                  display
                     schd_date
                     schd_time
                     schd_reference
                     schd_upd_qty
                     schd_fc_qual.
               end. /* END OF IF AVAILABLE schd_det */

               else do:
                  for first schd_det
                     where schd_type     = sch_type
                     and   schd_nbr      = sch_nbr
                     and   schd_line     = sch_line
                     and   schd_rlse_id  = sch_rlse_id
                     and   schd_interval = "D"
                     exclusive-lock:
                  end. /* FOR FIRST schd_det */
                  bell.
               end.  /* END OF ELSE DO */

            end. /* END OF IF LASTKEY = KEYCODE(F9) */

            else
               if lastkey = keycode("F10")
               or lastkey = keycode("CURSOR-DOWN")
               then do:
                  find next schd_det
                     where schd_type     = sch_type
                     and   schd_nbr      = sch_nbr
                     and   schd_line     = sch_line
                     and   schd_rlse_id  = sch_rlse_id
                     and   schd_interval = "D"
                  exclusive-lock no-error.

                  if available schd_det
                  then do:
                     down 1.
                     display
                        schd_date
                        schd_time
                        schd_reference
                        schd_upd_qty
                        schd_fc_qual.
                  end. /* END OF IF AVAILABLE schd_det */

                  else do:
                     find last schd_det
                        where schd_type     = sch_type
                        and   schd_nbr      = sch_nbr
                        and   schd_line     = sch_line
                        and   schd_rlse_id  = sch_rlse_id
                        and   schd_interval = "D"
                     exclusive-lock no-error.
                     bell.
                  end. /* END OF ELSE DO */

               end. /* END OF IF LASTKEY = KEYCODE(F10) */

         end.  /* END OF IF AVAILABLE schd_det */

         ststatus = stline[1].
         status input ststatus.
         pause before-hide.
         prompt-for schd_date schd_time schd_reference
            go-on(F9 F10 CURSOR-UP CURSOR-DOWN).
         pause 0.

         if frame-field = "schd_date"
         then
            next-prompt schd_date.
         else
         if frame-field = "schd_time"
         then
            next-prompt schd_time.
         else
         if frame-field = "schd_reference"
         then
            next-prompt schd_reference.

         if input schd_date = ?
         then do:
            {pxmsg.i &MSGNUM=27 &ERRORLEVEL=3} /* INVALID DATE */
            next-prompt schd_date with frame sched_det.
            undo , retry.
         end. /* END OF IF input schd_date = ? */

         assign
            l_ref_time  = substring(string(time,"HH:MM"),1,2)
                          + substring(string(time,"HH:MM"),4,2)
            l_msgnbr    = 0
            l_schd_time = input schd_time.

         /* FSTIMCHK WILL RETURN ONE OF TWO POTENTIAL  */
         /* ERRORS.  #30 IS FOR MINUTES > 59.  #69     */
         /* INDICATES NON-NUMERIC INPUT, IN WHICH CASE */
         /* WE WANT TO PRESERVE AND REDISPLAY THE USER */
         /* INPUT.                                     */

         {gprun.i ""fstimchk.p""
            "(input  ""T"",
              input  l_schd_time,
              input  """",
              output l_ref_time,
              output l_dummy_length,
              output l_msgnbr)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if l_msgnbr <> 0
         then do:
            {pxmsg.i &MSGNUM=l_msgnbr &ERRORLEVEL=3}
            next-prompt schd_time with frame sched_det.
            undo, retry.
         end. /* END OF IF l_msgnbr <> 0 */

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* END OF DO WHILE LASTKEY = KEYCODE("F9") */

      for first schd_det
         where schd_type      = sch_type
         and   schd_nbr       = sch_nbr
         and   schd_line      = sch_line
         and   schd_rlse_id   = sch_rlse_id
         and   schd_date      = input schd_date
         and   schd_time      = input schd_time
         and   schd_interval  = "D"
         and   schd_reference = input schd_reference
         exclusive-lock:
      end. /* FOR FIRST schd_det */

      if not available schd_det
      then do:
         new_schd_det = yes.
         /* ADDING NEW RECORD */
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
         create schd_det.
         assign
            schd_type = sch_type
            schd_nbr = sch_nbr
            schd_line = sch_line
            schd_rlse_id = sch_rlse_id
            schd_date
            schd_time
            schd_interval = "D"
            schd_reference.

         if recid(schd_det) = -1 then .

         schd_recid = recid(schd_det).
      end. /* END OF IF NOT AVAILABLE schd_det */

      else
         new_schd_det = no.

      assign
         schddet_recid = recid(schd_det)
         where_we_are  = frame-line.

      do i = 1 to where_we_are while available schd_det:
         find prev schd_det
            where schd_type     = sch_type
            and   schd_nbr      = sch_nbr
            and   schd_line     = sch_line
            and   schd_rlse_id  = sch_rlse_id
            and   schd_interval = "D"
         no-lock no-error.
      end. /* END OF DO = i TO where_we_are */

      up where_we_are - 1.

      do i = 1 to frame-down:
         find next schd_det
            where schd_type     = sch_type
            and   schd_nbr      = sch_nbr
            and   schd_line     = sch_line
            and   schd_rlse_id  = sch_rlse_id
            and   schd_interval = "D"
         no-lock no-error.

         if available schd_det
         then do:
            display
               schd_date
               schd_time
               schd_reference
               schd_upd_qty
               schd_fc_qual.

            if recid(schd_det) = schddet_recid
            then
               where_we_are = frame-line.

         end. /* END OF IF AVAILABLE schd_det */
         else
            display
               "" @ schd_date
               "" @ schd_time
               "" @ schd_reference
               "" @ schd_upd_qty
               "" @ schd_fc_qual.

         if i < frame-down
         then
            down 1.

      end. /* END OF DO i = 1 TO FRAME-DOWN */

      up frame-down - where_we_are.
      for first schd_det
         where recid(schd_det) = schddet_recid
         exclusive-lock:
      end. /* FOR FIRST schd_det */
      schddet_recid = recid(schd_det).
      ststatus = stline[2].
      status input ststatus.

      display
         schd_date
         schd_time
         schd_reference
         schd_upd_qty
         schd_fc_qual.

      do on error undo , retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         pause before-hide.

         assign
            l_old_schd_upd_qty = schd_upd_qty
            l_old_schd_fc_qual = schd_fc_qual

            /* LOGIC TO GET THE PREVIOUS MONDAY IN THE WEEK */
            l_date             = schd_date
                                 + integer(entry(weekday(schd_date),
                                 "-6,0,-1,-2,-3,-4,-5"))
            l_new_schd_upd_qty = input schd_upd_qty.

         prompt-for schd_upd_qty schd_fc_qual
            /*V8+*/
                  go-on(ESC F5 CTRL-D F9 F10 CURSOR-UP CURSOR-DOWN).   

         if input schd_fc_qual = "f"
            and pod_firm_days  = 0
         then do:
            /* FIRM NOT ALLWD, FIRM DAYS IS 0 */
            {pxmsg.i &MSGNUM=8198 &ERRORLEVEL=3}
            next-prompt schd_fc_qual.
            undo, retry.
         end. /* IF INPUT schd_fc_qual = "f" */
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* END OF DO ON ERROR UNDO , RETRY */

      if keyfunction(lastkey) = "END-ERROR"
      then do:
         undo detail-loop, retry detail-loop.
      end. /* IF KEYFUNCTION(LASTKEY) = "END-ERROR" */

      if frame-field = "schd_upd_qty"
      then
         next-prompt schd_upd_qty.
      else
      if frame-field = "schd_fc_qual"
      then
         next-prompt schd_fc_qual.

      do while lastkey = keycode("F9")
            or lastkey = keycode("CURSOR-UP")
            or lastkey = keycode("F10")
            or lastkey = keycode("CURSOR-DOWN"):
         new_schd_det = no.

         if lastkey = keycode("F9")
            or lastkey = keycode("CURSOR-UP")
         then do:

            assign
               l_old_schd_upd_qty = schd_upd_qty
               schd_upd_qty
               l_new_schd_upd_qty = input schd_upd_qty
               l_old_schd_fc_qual = schd_fc_qual
               schd_fc_qual
               l_new_schd_fc_qual = input schd_fc_qual
               new_date           = input schd_date
               l_schd_time        = input schd_time
               l_schd_interval    = ""
               l_schd_ref         = input schd_reference
               .

            if rsc_auto_update
               and sch_rlse_id = pod_curr_rlse_id[3]
               and pod_curr_rlse_id[2] = pod_curr_rlse_id[3]
            then do:
               /* ROUTINE TO AUTOMATICALLY UPDATE THE schd_qty IN
               PLANNING SCHEDULE */
               run pln_update
                 (input recid(sch_mstr),
                  input pod_curr_rlse_id[2],
                  input l_date,
                  input l_old_schd_upd_qty,
                  input l_new_schd_upd_qty).

               run fab_raw_update
                 (input recid(sch_mstr),
                  input pod_curr_rlse_id[2],
                  input new_date,
                  input l_old_schd_upd_qty,
                  input l_new_schd_upd_qty).
            end. /* IF rsc_auto_update */

            /* ROUTINE TO UPDATE SCHEDULE TYPE 4 WHEN THE
            SHIPPING SCHEDULE HAS CHANGED */

            if sch_rlse_id = pod_curr_rlse_id[3]
            then
               run sched_update
                 (input recid(sch_mstr),
                  input pod_curr_rlse_id[1],
                  input new_date,
                  input l_old_schd_upd_qty,
                  input l_new_schd_upd_qty,
                  input l_old_schd_fc_qual,
                  input l_new_schd_fc_qual,
                  input l_schd_time,
                  input l_schd_interval,
                  input l_schd_ref).

            find prev schd_det
               where schd_type     = sch_type
               and   schd_nbr      = sch_nbr
               and   schd_line     = sch_line
               and   schd_rlse_id  = sch_rlse_id
               and   schd_interval = "D"
            exclusive-lock no-error.

            if available schd_det
            then do:
               up 1.
               display
                  schd_date
                  schd_time
                  schd_reference
                  schd_upd_qty
                  schd_fc_qual.
            end. /* END OF IF AVAILABLE schd_det */
            else do:
               for first schd_det
                  where schd_type = sch_type
                  and   schd_nbr = sch_nbr
                  and   schd_line = sch_line
                  and   schd_rlse_id = sch_rlse_id
                  and   schd_interval = "D"
                  exclusive-lock:
               end. /* FOR FIRST schd_det */
               bell.
            end.  /* END OF ELSE DO */

         end. /* END OF IF LASTKEY = KEYCODE(F9)  */
         else
         if lastkey = keycode("F10")
            or lastkey = keycode("CURSOR-DOWN")
         then do:

            assign
               l_old_schd_upd_qty = schd_upd_qty
               schd_upd_qty
               l_new_schd_upd_qty = input schd_upd_qty
               l_old_schd_fc_qual = schd_fc_qual
               schd_fc_qual
               l_new_schd_fc_qual = input schd_fc_qual
               new_date           = input schd_date
               l_schd_time        = input schd_time
               l_schd_interval    = ""
               l_schd_ref         = input schd_reference
               .

            if rsc_auto_update
               and sch_rlse_id = pod_curr_rlse_id[3]
               and pod_curr_rlse_id[2] = pod_curr_rlse_id[3]
            then do:
               /* ROUTINE TO AUTOMATICALLY UPDATE THE schd_qty IN
                  PLANNING SCHEDULE */
               run pln_update
                 (input recid(sch_mstr),
                  input pod_curr_rlse_id[2],
                  input l_date,
                  input l_old_schd_upd_qty,
                  input l_new_schd_upd_qty).

               run fab_raw_update
                 (input recid(sch_mstr),
                  input pod_curr_rlse_id[2],
                  input new_date,
                  input l_old_schd_upd_qty,
                  input l_new_schd_upd_qty).

            end. /* IF rsc_auto_update */

            if sch_rlse_id = pod_curr_rlse_id[3]
            then
               run sched_update
                 (input recid(sch_mstr),
                  input pod_curr_rlse_id[1],
                  input new_date,
                  input l_old_schd_upd_qty,
                  input l_new_schd_upd_qty,
                  input l_old_schd_fc_qual,
                  input l_new_schd_fc_qual,
                  input l_schd_time,
                  input l_schd_interval,
                  input l_schd_ref).

            find next schd_det
               where schd_type     = sch_type
               and   schd_nbr      = sch_nbr
               and   schd_line     = sch_line
               and   schd_rlse_id  = sch_rlse_id
               and   schd_interval = "D"
            exclusive-lock no-error.

            if available schd_det
            then do:
               down 1.
               display
                  schd_date
                  schd_time
                  schd_reference
                  schd_upd_qty
                  schd_fc_qual.
            end. /* END OF IF AVAILABLE schd_det */
            else do:
               find last schd_det
                  where schd_type     = sch_type
                  and   schd_nbr      = sch_nbr
                  and   schd_line     = sch_line
                  and   schd_rlse_id  = sch_rlse_id
                  and   schd_interval = "D"
               exclusive-lock no-error.
               bell.
            end.  /* END OF ELSE DO */

         end.  /* END OF IF LASTKEY = KEYCODE(F10)  */

         ststatus = stline[2].
         status input ststatus.

         do on error undo , retry:
/*GUI*/ if global-beam-me-up then undo, leave.

            pause before-hide.
            prompt-for schd_upd_qty schd_fc_qual
               /*V8+*/
                     go-on(ESC F5 CTRL-D F9 F10 CURSOR-UP CURSOR-DOWN).   

            pause 0.

            if input schd_fc_qual = "f"
               and pod_firm_days = 0
            then do:
               /* FIRM NOT ALLWD, FIRM DAYS IS 0 */
               {pxmsg.i &MSGNUM=8198 &ERRORLEVEL=3}
               next-prompt schd_fc_qual.
               undo, retry.
            end. /* IF INPUT schd_fc_qual = "f" */
         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* END OF DO ON ERROR UNDO , RETRY */

         if frame-field = "schd_upd_qty"
         then
            next-prompt schd_upd_qty.
         else
         if frame-field = "schd_fc_qual"
         then
            next-prompt schd_fc_qual.

      end. /* END OF DO WHILE LASTKEY = KEYCODE("F9") */

      do while lastkey = keycode("F9")
            or lastkey = keycode("CURSOR-UP")
            or lastkey = keycode("F10")
            or lastkey = keycode("CURSOR-DOWN"):
         new_schd_det = no.

         if frame-field = "schd_upd_qty"
         then
            next-prompt schd_upd_qty.
         else
         if frame-field = "schd_fc_qual"
         then
            next-prompt schd_fc_qual.

      end. /* END OF DO WHILE LASTKEY = KEYCODE("F9") */

      if lastkey = keycode("F5")
         or lastkey = keycode("CTRL-D")
      then do:
            if  pod__qad07         <> ""
            and input schd_fc_qual = "F"
            then do:
               /* UNABLE TO DELETE FIRMED SCHEDULE WITH DELIVERY TIME */
               {pxmsg.i &MSGNUM=5597 &ERRORLEVEL=3}
               /* QUANTITY CAN BE SET TO ZERO INSTEAD */
               {pxmsg.i &MSGNUM=5598 &ERRORLEVEL=1}
               undo, retry.
            end. /* IF pod__qad07 <> "" AND ... */
            else do:
               del-yn = yes.
               /* CONFIRM DELETE */
               {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
            end. /* ELSE DO */

         if del-yn = no
         then do:
            display
               schd_date
               schd_time
               schd_reference
               schd_upd_qty
               schd_fc_qual.
            next detail-loop.
         end. /* IF del-yn = NO */

         for first schd_det
            where schd_type      = sch_type
            and   schd_nbr       = sch_nbr
            and   schd_line      = sch_line
            and   schd_rlse_id   = sch_rlse_id
            and   schd_date      = input schd_date
            and   schd_time      = input schd_time
            and   schd_interval  = "D"
            and   schd_reference = input schd_reference
            exclusive-lock:
         end. /* FOR FIRST schd_det */

         assign
            l_old_schd_upd_qty = schd_upd_qty
            l_new_schd_upd_qty = 0
            l_old_schd_fc_qual = schd_fc_qual
            l_new_schd_fc_qual = "P"
            new_date           = input schd_date
            l_schd_time        = input schd_time
            l_schd_interval    = ""
            l_schd_ref         = input schd_reference
            /* LOGIC TO GET THE PREVIOUS MONDAY IN THE WEEK */
            l_date             = schd_date
                               + integer(entry(weekday(schd_date),
                                         "-6,0,-1,-2,-3,-4,-5")).

         delete schd_det.

         if rsc_auto_update
            and sch_rlse_id = pod_curr_rlse_id[3]
            and pod_curr_rlse_id[2] = pod_curr_rlse_id[3]
         then do:
            /* ROUTINE TO AUTOMATICALLY UPDATE THE schd_qty IN
               PLANNING SCHEDULE */
            run pln_update
              (input recid(sch_mstr),
               input pod_curr_rlse_id[2],
               input l_date,
               input l_old_schd_upd_qty,
               input l_new_schd_upd_qty).

            run fab_raw_update
              (input recid(sch_mstr),
               input pod_curr_rlse_id[2],
               input new_date,
               input l_old_schd_upd_qty,
               input l_new_schd_upd_qty).

         end. /* IF rsc_auto_update */

         if sch_rlse_id = pod_curr_rlse_id[3]
         then
            run sched_update
              (input recid(sch_mstr),
               input pod_curr_rlse_id[1],
               input new_date,
               input l_old_schd_upd_qty,
               input l_new_schd_upd_qty,
               input l_old_schd_fc_qual,
               input l_new_schd_fc_qual,
               input l_schd_time,
               input l_schd_interval,
               input l_schd_ref).

         where_we_are = frame-line.

         find next schd_det
            where schd_type     = sch_type
            and   schd_nbr      = sch_nbr
            and   schd_line     = sch_line
            and   schd_rlse_id  = sch_rlse_id
            and   schd_interval = "D"
         no-lock no-error.

         if available schd_det
         then do:
            schddet_recid = recid(schd_det).
            display
               schd_date
               schd_time
               schd_reference
               schd_upd_qty
               schd_fc_qual.

            do i = where_we_are to frame-down - 1:
               down 1.
               find next schd_det
                  where schd_type     = sch_type
                  and   schd_nbr      = sch_nbr
                  and   schd_line     = sch_line
                  and   schd_rlse_id  = sch_rlse_id
                  and   schd_interval = "D"
               no-lock no-error.

               if available schd_det
               then
                  display
                     schd_date
                     schd_time
                     schd_reference
                     schd_upd_qty
                     schd_fc_qual.
               else
                  display
                     "" @ schd_date
                     "" @ schd_time
                     "" @ schd_reference
                     "" @ schd_upd_qty
                     "" @ schd_fc_qual.

            end. /* END OF DO i = where_we_are TO FRAME-DOWN - 1 */

            up frame-down - where_we_are.
            for first schd_det
               where recid(schd_det) = schddet_recid
            exclusive-lock:
            end. /* FOR FIRST schd_det */

         end. /* END OF IF AVAILABLE schd_det */
         else do:
            display
               "" @ schd_date
               "" @ schd_time
               "" @ schd_reference
               "" @ schd_upd_qty
               "" @ schd_fc_qual.

            find prev schd_det
               where schd_type     = sch_type
               and   schd_nbr      = sch_nbr
               and   schd_line     = sch_line
               and   schd_rlse_id  = sch_rlse_id
               and   schd_interval = "D"
            exclusive-lock no-error.

            if available schd_det
            then do:
               up 1.
               display
                  schd_date
                  schd_time
                  schd_reference
                  schd_upd_qty
                  schd_fc_qual.
            end. /* END OF IF AVAILABLE schd_det */

         end. /* END OF ELSE DO OF IF AVAILABLE schd_det */

      end. /* END OF IF LASTKEY = KEYCODE("F5") */
      else
      if keyfunction(lastkey) = "END-ERROR"
      then
         display
            schd_upd_qty
            schd_fc_qual.
      else do:
         assign
            l_old_schd_upd_qty = schd_upd_qty
            schd_upd_qty
            l_new_schd_upd_qty = input schd_upd_qty
            l_old_schd_fc_qual = schd_fc_qual
            schd_fc_qual
            l_new_schd_fc_qual = input schd_fc_qual
            new_date           = input schd_date
            l_schd_time        = input schd_time
            l_schd_interval    = ""
            l_schd_ref         = input schd_reference
            .

         if rsc_auto_update
            and sch_rlse_id = pod_curr_rlse_id[3]
            and pod_curr_rlse_id[2] = pod_curr_rlse_id[3]
         then do:
            /* ROUTINE TO AUTOMATICALLY UPDATE THE schd_qty IN
               PLANNING SCHEDULE */
            run pln_update
              (input recid(sch_mstr),
               input pod_curr_rlse_id[2],
               input l_date,
               input l_old_schd_upd_qty,
               input l_new_schd_upd_qty).

            run fab_raw_update
              (input recid(sch_mstr),
               input pod_curr_rlse_id[2],
               input new_date,
               input l_old_schd_upd_qty,
               input l_new_schd_upd_qty).
         end. /* IF rsc_auto_update */

         if sch_rlse_id = pod_curr_rlse_id[3]
         then
            run sched_update
              (input recid(sch_mstr),
               input pod_curr_rlse_id[1],
               input new_date,
               input l_old_schd_upd_qty,
               input l_new_schd_upd_qty,
               input l_old_schd_fc_qual,
               input l_new_schd_fc_qual,
               input l_schd_time,
               input l_schd_interval,
               input l_schd_ref).

         if new_schd_det
            and frame-line <> frame-down
         then do:
            assign
               schddet_recid = recid(schd_det)
               where_we_are = frame-line.

            do i = 1 to where_we_are + 1 while available schd_det:
               find prev schd_det
                  where schd_type     = sch_type
                  and   schd_nbr      = sch_nbr
                  and   schd_line     = sch_line
                  and   schd_rlse_id  = sch_rlse_id
                  and   schd_interval = "D"
               no-lock no-error.
            end. /* END OF DO i = 1 to where_we_are + 1 */

            up where_we_are - 1.

            do i = 1 to frame-down:
               find next schd_det
                  where schd_type     = sch_type
                  and   schd_nbr      = sch_nbr
                  and   schd_line     = sch_line
                  and   schd_rlse_id  = sch_rlse_id
                  and   schd_interval = "D"
               no-lock no-error.

               if available schd_det
               then do:
                  display
                     schd_date
                     schd_time
                     schd_reference
                     schd_upd_qty
                     schd_fc_qual.

                  if recid(schd_det) = schddet_recid
                  then
                     where_we_are = frame-line.

               end. /* END OF IF AVAILABLE schd_det */
               else
                  display
                     "" @ schd_date
                     "" @ schd_time
                     "" @ schd_reference
                     "" @ schd_upd_qty
                     "" @ schd_fc_qual.

               if i < frame-down
               then
                  down 1.
            end. /* END OF DO i = 1 TO FRAME-DOWN */

            up frame-down - where_we_are.
            for first schd_det
               where recid(schd_det) = schddet_recid
               exclusive-lock:
            end. /* FOR FIRST schd_det */
            schddet_recid = recid(schd_det).
         end. /* END OF IF new_schd_det & FRAME-LINE <> FRAME-DOWN */

      end. /* END OF ELSE DO */

   end. /* END OF REPEAT WITH FRAME sched_det: Detail loop */

   prior_cum_qty = sch_pcr_qty.
   for each schd_det
      where schd_type     = sch_type
      and   schd_nbr      = sch_nbr
      and   schd_line     = sch_line
      and   schd_rlse_id  = sch_rlse_id
      and   schd_interval = "D"
      exclusive-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


      if sch_cumulative
      then do:
         if schd_upd_qty < prior_cum_qty
         then do:
            /* CUM QTYS NOT IN ASCENDING ORDER */
            {pxmsg.i &MSGNUM=6009 &ERRORLEVEL=3}
            undo mainloop , retry mainloop.
         end. /* END OF IF schd_upd_qty < prioir_cum_qty */
         assign
            schd_cum_qty   = schd_upd_qty
            schd_discr_qty = schd_cum_qty  - prior_cum_qty
            prior_cum_qty  = prior_cum_qty + schd_discr_qty.
      end. /* END OF IF sch_cumulative */
      else
         assign
            schd_discr_qty = schd_upd_qty
            prior_cum_qty  = prior_cum_qty + schd_discr_qty
            schd_cum_qty   = prior_cum_qty.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* END OF FOR EACH schd_det */

end. /* END OF DO TRANSACTION WITH FRAME sched_det */

ststatus = stline[2].
status input ststatus.
hide frame sched_det no-pause.
pause before-hide.

PROCEDURE pln_update:

   define input parameter sch_recid          as recid                 no-undo.
   define input parameter l_pod_curr_rlse_id like pod_curr_rlse_id[2] no-undo.
   define input parameter l_date             as date                  no-undo.
   define input parameter l_old_schd_upd_qty like schd_upd_qty        no-undo.
   define input parameter l_new_schd_upd_qty like schd_upd_qty        no-undo.
   define buffer b_sch_mstr for sch_mstr.
   define buffer b_schd_det for schd_det.

   for first b_sch_mstr
      where recid(b_sch_mstr) = sch_recid
      no-lock:
   end. /* FOR FIRST b_sch_mstr */

   for first b_schd_det
      where schd_type    = 5
      and   schd_nbr     = b_sch_mstr.sch_nbr
      and   schd_line    = b_sch_mstr.sch_line
      and   schd_rlse_id = l_pod_curr_rlse_id
      and   schd_date    = l_date
      exclusive-lock:
   end. /* FOR FIRST b_schd_det */

   if available b_schd_det
   then do:
      if sch_cumulative
      then do:
         if schd_cum_qty - l_old_schd_upd_qty
            + l_new_schd_upd_qty > 0
         then
            schd_cum_qty = schd_cum_qty - l_old_schd_upd_qty
                           + l_new_schd_upd_qty.
         else
            schd_cum_qty = 0.
      end. /* IF sch_cumulative */
      else do:
         if schd_discr_qty - l_old_schd_upd_qty
            + l_new_schd_upd_qty > 0
         then
            schd_discr_qty = schd_discr_qty - l_old_schd_upd_qty
                             + l_new_schd_upd_qty.
         else
            schd_discr_qty = 0.
      end. /* ELSE DO: */
   end. /* END OF IF AVAILABLE schd_det */
END PROCEDURE. /* PROCEDURE pln_update */

PROCEDURE fab_raw_update:

   define input parameter sch_recid          as recid                 no-undo.
   define input parameter l_pod_curr_rlse_id like pod_curr_rlse_id[2] no-undo.
   define input parameter new_date           as date                  no-undo.
   define input parameter l_old_schd_upd_qty like schd_upd_qty        no-undo.
   define input parameter l_new_schd_upd_qty like schd_upd_qty        no-undo.
   define buffer b_sch_mstr for sch_mstr.
   define buffer b_sch_mstr2 for sch_mstr.
   define buffer b_sch_mstr3 for sch_mstr.

   for first b_sch_mstr
      where recid(b_sch_mstr) = sch_recid
      no-lock:
   end. /* FOR FIRST b_sch_mstr */

   for first b_sch_mstr2
      where b_sch_mstr2.sch_type    = 5
      and   b_sch_mstr2.sch_nbr     = b_sch_mstr.sch_nbr
      and   b_sch_mstr2.sch_line    = b_sch_mstr.sch_line
      and   b_sch_mstr2.sch_rlse_id = b_sch_mstr.sch_rlse_id
      exclusive-lock:
   end. /* FOR FIRST b_sch_mstr2 */

   if available b_sch_mstr2
   then do:

      if new_date >= b_sch_mstr2.sch_fab_strt
         and new_date <= b_sch_mstr2.sch_fab_end
      then
         b_sch_mstr2.sch_fab_qty = b_sch_mstr2.sch_fab_qty +
                                   (l_new_schd_upd_qty - l_old_schd_upd_qty).

      if new_date >= b_sch_mstr2.sch_raw_strt
         and new_date <= b_sch_mstr2.sch_raw_end
      then
         b_sch_mstr2.sch_raw_qty = b_sch_mstr2.sch_raw_qty +
                                   (l_new_schd_upd_qty - l_old_schd_upd_qty).
   end. /* IF AVAILABLE sch_mstr */

   for first b_sch_mstr3
      where b_sch_mstr3.sch_type    = 4
      and   b_sch_mstr3.sch_nbr     = b_sch_mstr.sch_nbr
      and   b_sch_mstr3.sch_line    = b_sch_mstr.sch_line
      and   b_sch_mstr3.sch_rlse_id = b_sch_mstr.sch_rlse_id
      exclusive-lock:
   end. /* FOR FIRST b_sch_mstr3 */

   if available b_sch_mstr3
   then do:

      if new_date >= b_sch_mstr3.sch_fab_strt
         and new_date <= b_sch_mstr3.sch_fab_end
      then
         b_sch_mstr3.sch_fab_qty = b_sch_mstr3.sch_fab_qty +
                                   (l_new_schd_upd_qty - l_old_schd_upd_qty).

      if new_date >= b_sch_mstr3.sch_raw_strt
         and new_date <= b_sch_mstr3.sch_raw_end
      then
         b_sch_mstr3.sch_raw_qty = b_sch_mstr3.sch_raw_qty +
                                   (l_new_schd_upd_qty - l_old_schd_upd_qty).

   end. /* IF AVAILABLE b_sch_mstr3 */

END PROCEDURE. /* PROCEDURE fab_raw_update */

PROCEDURE sched_update:

   define input parameter sch_recid          as recid                 no-undo.
   define input parameter l_pod_curr_rlse_id like pod_curr_rlse_id[1] no-undo.
   define input parameter new_date           as date                  no-undo.
   define input parameter l_old_schd_upd_qty like schd_upd_qty        no-undo.
   define input parameter l_new_schd_upd_qty like schd_upd_qty        no-undo.
   define input parameter l_old_schd_fc_qual like schd_fc_qual        no-undo.
   define input parameter l_new_schd_fc_qual like schd_fc_qual        no-undo.
   define input parameter l_schd_time        like schd_time           no-undo.
   define input parameter l_schd_interval    like schd_interval       no-undo.
   define input parameter l_schd_ref         like schd_reference      no-undo.

   define variable l_cum_qty                 like schd_cum_qty        no-undo.
   define variable l_firm_lines              as integer initial 0     no-undo.
   define variable l_planned_lines           as integer initial 0     no-undo.
   define variable l_time_flag          like mfc_logical  initial no  no-undo.
   define variable l_planned_lines_flag like mfc_logical  initial no  no-undo.
   define variable l_planned_qty        like schd_upd_qty initial 0   no-undo.

   define buffer   b_sch_mstr           for  sch_mstr.
   define buffer   b_schd_det           for  schd_det.
   define buffer   type4_sch_mstr       for  sch_mstr.

   /********************* USAGE OF VARIABLES **************************/
   /* l_firm_lines         - FIRM(F) LINES COUNTER                    */
   /* l_planned_lines      - PLANNED(P) LINES COUNTER                 */
   /* l_time_flag          - INDICATES IF THERE ARE > 1 FIRM LINES    */
   /* l_planned_lines_flag - INDICATES IF THERE ARE > 1 PLANNED LINES */
   /* l_planned_qty        - TOTAL OF ALL PLANNED LINES               */
   /********************* USAGE OF VARIABLES **************************/

   for first b_sch_mstr
      where recid(b_sch_mstr) = sch_recid
      no-lock:
   end. /* FOR FIRST b_sch_mstr */

   for each b_schd_det
      where schd_type    =  6
      and   schd_nbr     =  b_sch_mstr.sch_nbr
      and   schd_line    =  b_sch_mstr.sch_line
      and   schd_rlse_id =  l_pod_curr_rlse_id
      and   schd_date    =  new_date
      no-lock:

      if schd_fc_qual = "f"
      then do:
         /* COUNT THE NUMBER OF FIRM SCHEDULE LINES */
         l_firm_lines = l_firm_lines + 1.

         /* SET FLAG IF NUMBER OF FIRM SCHEDULE LINES > 1 FOR THE SAME DATE */
         if schd_time <> l_schd_time
         then
            l_time_flag = yes.
      end. /* IF schd_fc_qual = "f"  */
      else if schd_fc_qual = "p"
      then
         /* COUNT THE NUMBER OF PLANNED SCHEDULE LINES */
         /* , ADD-UP AND STORE THE TOTAL OF ALL LINES  */
         assign
            l_planned_lines = l_planned_lines + 1
            l_planned_qty   = l_planned_qty   + schd_upd_qty.
   end. /* FOR EACH b_schd_det */

   for first b_schd_det
      where schd_type    = 4
      and   schd_nbr     = b_sch_mstr.sch_nbr
      and   schd_line    = b_sch_mstr.sch_line
      and   schd_rlse_id = l_pod_curr_rlse_id
      and   schd_date    = new_date
      exclusive-lock:
   end. /* FOR FIRST b_schd_det */

   if available b_schd_det
   then do:

      /* CHANGES TO TYPE 6 SCHEDULE MUST ALWAYS BE REFLECTED IN  */
      /* TYPE 4 SCHEDULE. WE UPDATE schd_cum_qty, schd_discr_qty */
      /* AND schd_upd_qty IRRESPECTIVE OF FLAG sch_cumulative.   */
      /* TYPE 4 and TYPE 6 SCHEDULES SHOULD ALWAYS BE IN SYNC.   */

      /* FOR MULTIPLE FIRMED ("F") LINES IN A       */
      /* SCHEDULE, RESET QUANTITIES IF schd_fc_qual */
      /* IS MODIFIED FROM 'F' TO 'P' OR VICE-VERSA  */
      if l_firm_lines > 1
      then do:
         if l_old_schd_fc_qual <> l_new_schd_fc_qual
         then do:
            if l_new_schd_fc_qual = "f"
            then
               l_old_schd_upd_qty = 0.
            else if l_new_schd_fc_qual = "p"
            then
               l_new_schd_upd_qty = 0.
         end. /* IF l_old_schd_fc_qual <> l_new_schd_fc_qual */
         else if (l_new_schd_fc_qual   = "p"
                  and l_new_schd_upd_qty = 0 )
         then
            /* WHEN MORE THAN 1 'F' & 'P' LINES */
            /* EXIST AND A 'P' LINE IS DELETED  */
            l_old_schd_upd_qty = 0.
      end. /* IF l_firm_lines > 1 */

      /* FOR MULTIPLE PLANNED ("P") LINES IN A        */
      /* SCHEDULE, RECALCULATE QUANTITIES AND SET     */
      /* FLAG IF NUMBER OF PLANNED SCHEDULE LINES > 1 */
      if l_planned_lines >= 1
      then do:
         if l_new_schd_fc_qual = "p"
         then do:
            if l_firm_lines = 0
            then
               /* GET THE TOTAL OF ALL PLANNED LINES    */
               assign
                  schd_discr_qty = l_planned_qty
                  schd_fc_qual   = l_new_schd_fc_qual.
            else if (l_firm_lines <> 0
                 and l_new_schd_fc_qual = l_old_schd_fc_qual
                 and l_new_schd_upd_qty = l_old_schd_upd_qty)
            then
               schd_discr_qty     = schd_discr_qty + l_new_schd_upd_qty
                                                   - l_old_schd_upd_qty.
            else if (l_firm_lines <> 0
                 and l_new_schd_fc_qual = l_old_schd_fc_qual
                 and l_new_schd_upd_qty <>  l_old_schd_upd_qty)
            then
               if schd_fc_qual = "P"
               then
                  schd_discr_qty = l_planned_qty.
               else
                  assign
                     l_new_schd_upd_qty =  0
                     l_old_schd_upd_qty =  0
                     schd_discr_qty     = schd_discr_qty + l_new_schd_upd_qty
                                                         - l_old_schd_upd_qty.
            else
               assign
                  l_new_schd_upd_qty =  0
                  schd_discr_qty     = schd_discr_qty + l_new_schd_upd_qty
                                                      - l_old_schd_upd_qty.

            l_planned_lines_flag = yes.
         end. /* IF l_new_schd_fc_qual = "p" */
         else
            l_planned_lines_flag = no.
      end. /* IF l_planned_lines > 1 */

      /* WHEN SINGLE 'F' LINE IS MODIFIED */
      if l_firm_lines <= 1
      then do:
         /* SINGLE LINE MODIFIED FROM 'F' TO 'P' OR DELETED */
         if schd_fc_qual = "f"
            and l_new_schd_fc_qual   = "p"
            and ((l_new_schd_upd_qty = 0 )
                  or (l_old_schd_fc_qual <> l_new_schd_fc_qual ))
            and not l_time_flag
            and not l_planned_lines_flag
         then do:
            schd_fc_qual = l_new_schd_fc_qual.
            /* WHEN A SINGLE "F" LINE IS DELETED */
            if l_new_schd_fc_qual     = "p"
               and l_new_schd_upd_qty = 0
            then
               l_new_schd_upd_qty = 0.

            schd_discr_qty = schd_discr_qty + l_new_schd_upd_qty
                                            - l_old_schd_upd_qty.
         end. /* IF schd_fc_qual = "f" */

         /* WHEN BEFORE MODIFICATION THERE EXIST > 1 "F"   */
         /* LINES AND AFTER MODIFICATION = 1 OR 0 "F" LINE */
         else if l_time_flag
              and not l_planned_lines_flag
         then do:
            if l_old_schd_fc_qual = l_new_schd_fc_qual
               or l_firm_lines    = 1
               or l_old_schd_upd_qty  = l_new_schd_upd_qty
            then
               l_old_schd_upd_qty = 0.
            assign
               l_new_schd_upd_qty = 0
               schd_discr_qty     = schd_discr_qty + l_new_schd_upd_qty
                                                   - l_old_schd_upd_qty.
         end. /* ELSE IF l_time_flag */

         /* WHEN SINGLE 'P' LINE IS MODIFIED */
         else if l_planned_lines <= 1
            and l_firm_lines = 0
            and not l_planned_lines_flag
         then
            assign
               schd_fc_qual   = l_new_schd_fc_qual
               schd_discr_qty = schd_discr_qty + l_new_schd_upd_qty
                                               - l_old_schd_upd_qty.

         /* FOR ALL OTHER POSSIBLE SCENARIOS */
         else if not l_planned_lines_flag
         then
            assign
               schd_discr_qty = l_new_schd_upd_qty
               schd_fc_qual   = l_new_schd_fc_qual.
      end. /* IF l_firm_lines <= 1 */

      /* FOR MULTIPLE FIRMED ("F") LINES, ADD-UP */
      /* THE LINE VALUES INTO schd_discr_qty     */
      if l_firm_lines > 1
         and not l_planned_lines_flag
      then do:
         if schd_fc_qual = "P"
         and l_new_schd_fc_qual = "F"
         then
            assign
               schd_discr_qty = l_new_schd_upd_qty
               schd_fc_qual   = "F".
         else
            schd_discr_qty = schd_discr_qty + l_new_schd_upd_qty
                                            - l_old_schd_upd_qty.

      end. /* IF l_firm_lines > 1 AND .. */

      if l_firm_lines >= 1
      and (schd_discr_qty = 0 or schd_fc_qual = "P")
      and l_planned_lines >= 1
      and l_planned_qty <> 0
      then
         /* GET THE TOTAL OF ALL PLANNED LINES    */
         assign
            schd_discr_qty = l_planned_qty
            schd_fc_qual   = "P".

   end. /* END OF IF AVAILABLE schd_det */

   if not available b_schd_det and new_date <> ?
   then do:
      create schd_det.
      assign
         schd_det.schd_type      = 4
         schd_det.schd_nbr       = b_sch_mstr.sch_nbr
         schd_det.schd_line      = b_sch_mstr.sch_line
         schd_det.schd_rlse_id   = l_pod_curr_rlse_id
         schd_det.schd_date      = new_date
         schd_det.schd_time      = l_schd_time
         schd_det.schd_interval  = l_schd_interval
         schd_det.schd_reference = l_schd_ref
         schd_det.schd_discr_qty = l_new_schd_upd_qty
         schd_det.schd_fc_qual   = l_new_schd_fc_qual
         .

      if recid(schd_det) = -1 then .
   end. /* IF NOT AVAILABLE b_schd_det ... */

   /* TYPE 4 SCHEDULE MASTER UPDATED WITH sch_pcr_qty AND   */
   /* sch_pcs_date FROM TYPE 6 SCHEDULE MASTER.             */

   l_cum_qty = sch_pcr_qty.

   for first type4_sch_mstr where
      type4_sch_mstr.sch_type    = 4                   and
      type4_sch_mstr.sch_nbr     = b_sch_mstr.sch_nbr  and
      type4_sch_mstr.sch_line    = b_sch_mstr.sch_line and
      type4_sch_mstr.sch_rlse_id = b_sch_mstr.sch_rlse_id
   exclusive-lock:
   assign
      type4_sch_mstr.sch_pcr_qty  = l_cum_qty
      type4_sch_mstr.sch_pcs_date = b_sch_mstr.sch_pcs_date.
   end. /* FOR FIRST type4_sch_mstr */

   /* UPDATING schd_det RECORDS FOR FIELDS schd_upd_qty AND */
   /* schd_cum_qty DEPENDING ON VALUE IN schd_discr_qty.    */

   for each b_schd_det where
         b_schd_det.schd_type    = 4                      and
         b_schd_det.schd_nbr     = b_sch_mstr.sch_nbr     and
         b_schd_det.schd_line    = b_sch_mstr.sch_line    and
         b_schd_det.schd_rlse_id = l_pod_curr_rlse_id
      exclusive-lock:

      assign
         b_schd_det.schd_upd_qty = b_schd_det.schd_discr_qty
         l_cum_qty               = l_cum_qty + b_schd_det.schd_discr_qty
         b_schd_det.schd_cum_qty = l_cum_qty.

   end. /* FOR EACH b_schd_det */

END PROCEDURE. /* PROCEDURE sched_update */
